#ifndef SQLITE_HELPER_H
#define SQLITE_HELPER_H

#include <memory>
#include <QDebug>
#include <QSqlDatabase>
#include <QSqlQuery>

#include "sqlite_command_interface.h"
#include "sqlite_query_interface.h"

class SqlHelperInterface {
public:
    virtual ~SqlHelperInterface() = default;

    virtual bool Initialize(const QString &database_name, const QString &connect_name) = 0;
    virtual bool ExecuteCommand(std::unique_ptr<SqliteCommandInterface> &&cmd) = 0;
    virtual bool ExecuteCommand(std::shared_ptr<SqliteCommandInterface> &&cmd) = 0;
    virtual std::optional<QSqlQuery> ExecuteQuery(std::unique_ptr<SqliteQueryInterface> &&query) = 0;
    virtual std::optional<QSqlQuery> ExecuteQuery(std::shared_ptr<SqliteQueryInterface> &&query) = 0;
    virtual void Close() = 0;
};

class SqliteHelper : SqlHelperInterface
{
public:
    SqliteHelper() = default;
    ~SqliteHelper() override;

    bool Initialize(const QString &database_name, const QString &connect_name) override;
    bool ExecuteCommand(std::unique_ptr<SqliteCommandInterface> &&cmd) override;
    bool ExecuteCommand(std::shared_ptr<SqliteCommandInterface> &&cmd) override;
    std::optional<QSqlQuery> ExecuteQuery(std::unique_ptr<SqliteQueryInterface> &&query) override;
    std::optional<QSqlQuery> ExecuteQuery(std::shared_ptr<SqliteQueryInterface> &&query) override;
    void Close() override;

    // 用于Debug
    QSqlDatabase GetDataBase();
private:
    QSqlDatabase database_;
};

#endif // SQLITE_HELPER_H
